package cn.tx.redis7.controller;

import cn.tx.redis7.domain.TUser;
import cn.tx.redis7.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

/**
 * @author jizenan
 * @date 2025/6/4
 * Description:
 */
@Api(tags = "客户接口+布隆过滤器")
@RestController
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("数据库初始化两条记录")
    @PostMapping("/customer/add")
    public void addUser(){
        for (int i = 0; i < 2; i++) {
            TUser tUser = new TUser();
            //tUser.setId(i);//注解设置就行
            tUser.setAccount(UUID.randomUUID().toString());
            tUser.setPassword("xxxxxxx");
            tUser.setNickname("customer"+i);
            userService.addCustomer(tUser);
        }
    }

    @ApiOperation("根据id查询")
    @GetMapping("/customer/{id}")
    public TUser findUserById(@PathVariable Integer id){
        return userService.findUserById(id);
    }

    @ApiOperation("BloomFilter,根据id查询")
    @GetMapping("/customerbloomfilter/{id}")
    public TUser findCustomerByIdWithBloomFilter(@PathVariable Integer id){
        return userService.findCustomerByIdWithBloomFilter(id);
    }
}
